package com.syw.houmao.main.thread;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2016/10/20.
 */

public class ThreadPool  extends ThreadPoolExecutor{
    private static ThreadPool pool ;
        private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
        private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
        private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
        private static final long KEEP_ALIVE = 1;
    public static BlockingQueue<Runnable> mQueue = new LinkedBlockingQueue<>(100);
    private ThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
    }

    public static ThreadPool getPool(){
        if(pool==null){
            synchronized (ThreadPool.class){
                if(pool==null){
                    return new ThreadPool(CORE_POOL_SIZE,MAXIMUM_POOL_SIZE,KEEP_ALIVE,TimeUnit.SECONDS,mQueue);
                }
            }
        }
        return pool;
    }

}

